//
//  SingleProductViewController.m
//  FlyGift
//
//  Created by lanou3g on 15/7/11.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "SingleProductViewController.h"
#import "BrandZoneViewController.h"
#import "SingleViewController.h"
#import "BrandHomeViewController.h"

@interface SingleProductViewController ()  <UITableViewDelegate>
@property(nonatomic,strong)BrandZoneViewController *brandViewVc;
@property(nonatomic,strong)SingleViewController *singleViewVc;

@end

@implementation SingleProductViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.translucent = NO;
    self.view.backgroundColor = [UIColor whiteColor];
    // 添加视图控制器
    self.brandViewVc = [[BrandZoneViewController alloc]init];
    [self.view addSubview:self.brandViewVc.view];
    self.singleViewVc = [[SingleViewController alloc]init];
    // 加载分段控件
    [self addSegmentedControl];
    
    __block SingleProductViewController *blockSelf = self;
    self.brandViewVc.brandZoneBlock = ^(NSString *string,NSNumber *number){
        [blockSelf jumpToBrandHomeViewWithString:string number:number];
    };
}

- (void)jumpToBrandHomeViewWithString:(NSString *)string number:(NSNumber*)number
{
    BrandHomeViewController *brandHome = [[BrandHomeViewController alloc]init];
    brandHome.imageName = string;
    brandHome.number = number;
    [self.navigationController pushViewController:brandHome animated:YES];
}

-  (void)addSegmentedControl
{
    NSArray *array = @[@"品牌",@"单品"];
    UISegmentedControl *segment = [[UISegmentedControl alloc]initWithItems:array];
    self.navigationItem.titleView = segment;
    [segment setWidth:kP6width(80) forSegmentAtIndex:0];
    [segment setWidth:kP6width(80) forSegmentAtIndex:1];
    segment.tintColor = [UIColor whiteColor];
    [segment addTarget:self action:@selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];
    // 开始进入页面 显示品牌区域页面
    segment.selectedSegmentIndex = 0;
}

#pragma mark - 点击segment切换页面
- (void)segmentedAction:(UISegmentedControl *)segment
{
    if (segment.selectedSegmentIndex == 0) {
        [self.view addSubview:self.brandViewVc.view];
        [self.singleViewVc.view removeFromSuperview];
    }else
    {
        [self.view addSubview:self.singleViewVc.view];
        [self.brandViewVc.view removeFromSuperview];
    }
}




@end
    
  
